/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package com.pancho;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;

public class DoctorDAO {
	public static Doctor loadDoctorByORMID(int idDoctor) throws PersistentException {
		try {
			PersistentSession session = com.pancho.Taller1PDSPersistentManager.instance().getSession();
			return loadDoctorByORMID(session, idDoctor);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Doctor getDoctorByORMID(int idDoctor) throws PersistentException {
		try {
			PersistentSession session = com.pancho.Taller1PDSPersistentManager.instance().getSession();
			return getDoctorByORMID(session, idDoctor);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Doctor loadDoctorByORMID(int idDoctor, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = com.pancho.Taller1PDSPersistentManager.instance().getSession();
			return loadDoctorByORMID(session, idDoctor, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Doctor getDoctorByORMID(int idDoctor, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = com.pancho.Taller1PDSPersistentManager.instance().getSession();
			return getDoctorByORMID(session, idDoctor, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Doctor loadDoctorByORMID(PersistentSession session, int idDoctor) throws PersistentException {
		try {
			return (Doctor) session.load(com.pancho.Doctor.class, new Integer(idDoctor));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Doctor getDoctorByORMID(PersistentSession session, int idDoctor) throws PersistentException {
		try {
			return (Doctor) session.get(com.pancho.Doctor.class, new Integer(idDoctor));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Doctor loadDoctorByORMID(PersistentSession session, int idDoctor, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Doctor) session.load(com.pancho.Doctor.class, new Integer(idDoctor), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Doctor getDoctorByORMID(PersistentSession session, int idDoctor, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Doctor) session.get(com.pancho.Doctor.class, new Integer(idDoctor), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Doctor[] listDoctorByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = com.pancho.Taller1PDSPersistentManager.instance().getSession();
			return listDoctorByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Doctor[] listDoctorByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = com.pancho.Taller1PDSPersistentManager.instance().getSession();
			return listDoctorByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Doctor[] listDoctorByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From com.pancho.Doctor as Doctor");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Doctor[]) list.toArray(new Doctor[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Doctor[] listDoctorByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From com.pancho.Doctor as Doctor");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Doctor[]) list.toArray(new Doctor[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Doctor loadDoctorByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = com.pancho.Taller1PDSPersistentManager.instance().getSession();
			return loadDoctorByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Doctor loadDoctorByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = com.pancho.Taller1PDSPersistentManager.instance().getSession();
			return loadDoctorByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Doctor loadDoctorByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Doctor[] doctors = listDoctorByQuery(session, condition, orderBy);
		if (doctors != null && doctors.length > 0)
			return doctors[0];
		else
			return null;
	}
	
	public static Doctor loadDoctorByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Doctor[] doctors = listDoctorByQuery(session, condition, orderBy, lockMode);
		if (doctors != null && doctors.length > 0)
			return doctors[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateDoctorByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = com.pancho.Taller1PDSPersistentManager.instance().getSession();
			return iterateDoctorByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateDoctorByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = com.pancho.Taller1PDSPersistentManager.instance().getSession();
			return iterateDoctorByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateDoctorByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From com.pancho.Doctor as Doctor");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateDoctorByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From com.pancho.Doctor as Doctor");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Doctor createDoctor() {
		return new com.pancho.Doctor();
	}
	
	public static boolean save(com.pancho.Doctor doctor) throws PersistentException {
		try {
			com.pancho.Taller1PDSPersistentManager.instance().saveObject(doctor);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean delete(com.pancho.Doctor doctor) throws PersistentException {
		try {
			com.pancho.Taller1PDSPersistentManager.instance().deleteObject(doctor);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean deleteAndDissociate(com.pancho.Doctor doctor)throws PersistentException {
		try {
			if(doctor.getBabyMonitor() != null) {
				doctor.getBabyMonitor().setDoctoridDoctor(null);
			}
			
			return delete(doctor);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean deleteAndDissociate(com.pancho.Doctor doctor, org.orm.PersistentSession session)throws PersistentException {
		try {
			if(doctor.getBabyMonitor() != null) {
				doctor.getBabyMonitor().setDoctoridDoctor(null);
			}
			
			try {
				session.delete(doctor);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean refresh(com.pancho.Doctor doctor) throws PersistentException {
		try {
			com.pancho.Taller1PDSPersistentManager.instance().getSession().refresh(doctor);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean evict(com.pancho.Doctor doctor) throws PersistentException {
		try {
			com.pancho.Taller1PDSPersistentManager.instance().getSession().evict(doctor);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Doctor loadDoctorByCriteria(DoctorCriteria doctorCriteria) {
		Doctor[] doctors = listDoctorByCriteria(doctorCriteria);
		if(doctors == null || doctors.length == 0) {
			return null;
		}
		return doctors[0];
	}
	
	public static Doctor[] listDoctorByCriteria(DoctorCriteria doctorCriteria) {
		return doctorCriteria.listDoctor();
	}
}
